/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.variable.dtgenerator.api.mginterface.resinfo;

import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.designtime.api.variable.CommonVariableEntity;
import com.inspur.edp.cef.generator.apiGenerator.CefApiGeneratorContext;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.MgrInterfaceGeneratorContext;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.resourceInfo.ModelInfoBaseGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.resourceInfo.ModelInfoCtorGenerator;
import com.inspur.edp.cef.variable.core.manager.VarMgrResInfoImpl;
import java.util.ArrayList;

public class VarModelInfoGenerator extends ModelInfoBaseGenerator {

  private CefApiGeneratorContext privateParentContext;
  private final CommonVariableEntity unifiedDataTypeDef;

  public VarModelInfoGenerator(
      CefApiGeneratorContext parentContext, CommonVariableEntity unifiedDataTypeDef) {
    super(parentContext);
    this.privateParentContext = parentContext;
    this.unifiedDataTypeDef = unifiedDataTypeDef;
  }

  @Override
  protected String getModelCode() {
    return unifiedDataTypeDef.getCode();
  }

  @Override
  protected String getModelDisplayValueKey() {
    return unifiedDataTypeDef.getI18nResourceInfoPrefix() + ".Name";
  }

  @Override
  protected String getModelRootNodeCode() {
    return unifiedDataTypeDef.getCode();
  }

  @Override
  protected Class getParentClassType() {
    return VarMgrResInfoImpl.class;
  }

  @Override
  protected ModelInfoCtorGenerator getModelInfoCtorGenerator() {
    return new VarModelInfoCtorGenerator(getName(), getMetaCurrentSU(), getMetaResourceMetaId(),
        getModelRootNodeCode(), getModelDisplayValueKey(), privateParentContext);
  }

  @Override
  protected ArrayList<ClassMethodGenerator> createMethodGenerators() {
    ArrayList<ClassMethodGenerator> list = super.createMethodGenerators();
    if (list == null) {
      list = new ArrayList<>();
    }
    list.add(
        new VarModelInfoGetResourceGenerator(getName(), getMetaCurrentSU(), getMetaResourceMetaId(),
            getModelRootNodeCode(), getModelDisplayValueKey(), privateParentContext));
    return list;
  }
}
